package com.java.zhuiyun.api.feedback.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java.zhuiyun.api.feedback.entity.Feedback;
import com.java.zhuiyun.api.feedback.mapper.FeedbackMapper;
import com.java.zhuiyun.api.feedback.service.IFeedbackService;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName FeedbackServiceImpl
 * @Description TODO
 * @Author xy
 * @Date 2023/9/14 10:47
 **/
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements IFeedbackService {
    @Resource
    JavaMailSender javaMailSender;

    /**
    * @Author xy
    * @Description TODO 审核成功
    * @Date 2023/9/27 8:25
    * @Return  * @param null
    */
    @Override
    public boolean FeedbackSucceed(Feedback feedback, MultipartFile file) {
        if (feedback.getId() == null){
            Date now = new Date();
            feedback.setTime(now);
            return save(feedback);
        }else {
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            simpleMailMessage.setFrom("2108801854@qq.com");
            simpleMailMessage.setTo(feedback.getEmail());
            simpleMailMessage.setText("您好！感谢您的反馈，经过审核，我们已经审核完成并已收到您的回馈。我们将根据您的反馈进行改进，非常感谢您的支持与陪伴(≧∇≦)。");
            simpleMailMessage.setSubject("成语大天才");
            System.out.println("开始发送");
            javaMailSender.send(simpleMailMessage);
            System.out.println("发送完成");
            return updateById(feedback);
        }
    }

    /**
    * @Author xy
    * @Description TODO 审核失败
    * @Date 2023/10/8 13:43
    * @Return  * @param null
    */
    @Override
    public boolean FeedbackFail(Feedback feedback, MultipartFile file) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("2108801854@qq.com");
        simpleMailMessage.setTo(feedback.getEmail());
        simpleMailMessage.setText("您好！感谢您的反馈，经过审核，我们发现您提交的反馈内容中包含违规图片，因此未能通过审核。请您检查内容和图片，并重新提交您的反馈。感谢您的理解与合作。");
        simpleMailMessage.setSubject("成语大天才");
        System.out.println("开始发送");
        javaMailSender.send(simpleMailMessage);
        System.out.println("发送完成");
        return updateById(feedback);
    }
}
